Toolbar

(SESL variant) A standard toolbar for use within application content.

A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setSupportActionBar() method.

Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar may contain a combination of the following optional elements:

  • A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app's choosing. This button should always be used to access other navigational destinations within the container of the Toolbar and its signified content or otherwise leave the current context signified by the Toolbar. The navigation button is vertically aligned within the Toolbar's minimum height, if set.
  • A branded logo image. This may extend to the height of the bar and can be arbitrarily wide.
  • A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.
  • One or more custom views. The application may add arbitrary child views to the Toolbar. They will appear at this position within the layout. If a child view's LayoutParams indicates a Gravity value of CENTER_HORIZONTAL the view will attempt to center within the available space remaining in the Toolbar after all other elements have been measured.
  • An action menu. The menu of actions will pin to the end of the Toolbar offering a few frequent, important or typical actions along with an optional overflow menu for additional actions. Action buttons are vertically aligned within the Toolbar's minimum height, if set.

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

buttonGravitycollapseContentDescriptioncollapseIconcontentInsetEndcontentInsetLeftcontentInsetRightcontentInsetStartcontentInsetStartWithNavigationcontentInsetEndWithActionsgravitylogologoDescriptionmaxButtonHeightnavigationContentDescriptionnavigationIconpopupThemesubtitlesubtitleTextAppearancesubtitleTextColortitletitleMargintitleMarginBottomtitleMarginEndtitleMarginStarttitleMarginToptitleTextAppearancetitleTextColormenu

Constructors

Link copied to clipboard
constructor(@NonNull context: @NonNull Context)
constructor(@NonNull context: @NonNull Context, @Nullable attrs: @Nullable AttributeSet)
constructor(@NonNull context: @NonNull Context, @Nullable attrs: @Nullable AttributeSet, defStyleAttr: Int)

Types

Link copied to clipboard
Layout information for child views of Toolbars.
Link copied to clipboard
Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners.
Link copied to clipboard

Functions

Link copied to clipboard
open fun addMenuProvider(@NonNull provider: @NonNull MenuProvider)
open fun addMenuProvider(@NonNull provider: @NonNull MenuProvider, @NonNull owner: @NonNull LifecycleOwner)
open fun addMenuProvider(@NonNull provider: @NonNull MenuProvider, @NonNull owner: @NonNull LifecycleOwner, state: @NonNull Lifecycle.State)
Link copied to clipboard
Link copied to clipboard
Collapse a currently expanded action view.
Link copied to clipboard
Dismiss all currently showing popup menus, including overflow or submenus.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@Nullable
open fun getCollapseContentDescription(): @Nullable CharSequence
Retrieve the currently configured content description for the collapse button view.
Link copied to clipboard
@Nullable
open fun getCollapseIcon(): @Nullable Drawable
Return the current drawable used as the collapse icon.
Link copied to clipboard
Gets the ending content inset for this toolbar.
Link copied to clipboard
Gets the end content inset to use when action buttons are present.
Link copied to clipboard
Gets the left content inset for this toolbar.
Link copied to clipboard
Gets the right content inset for this toolbar.
Link copied to clipboard
Gets the starting content inset for this toolbar.
Link copied to clipboard
Gets the start content inset to use when a navigation button is present.
Link copied to clipboard
Gets the content inset that will be used on the ending side of the bar in the current toolbar configuration.
Link copied to clipboard
Gets the content inset that will be used on the left side of the bar in the current toolbar configuration.
Link copied to clipboard
Gets the content inset that will be used on the right side of the bar in the current toolbar configuration.
Link copied to clipboard
Gets the content inset that will be used on the starting side of the bar in the current toolbar configuration.
Link copied to clipboard
open fun getLogo(): Drawable
Return the current logo drawable.
Link copied to clipboard
Return the description of the toolbar's logo.
Link copied to clipboard
open fun getMenu(): Menu
Return the Menu shown in the toolbar.
Link copied to clipboard
@Nullable
open fun getNavigationContentDescription(): @Nullable CharSequence
Retrieve the currently configured content description for the navigation button view.
Link copied to clipboard
@Nullable
open fun getNavigationIcon(): @Nullable Drawable
Return the current drawable used as the navigation icon.
Link copied to clipboard
@Nullable
open fun getOverflowIcon(): @Nullable Drawable
Return the current drawable used as the overflow icon.
Link copied to clipboard
Link copied to clipboard
Return the subtitle of this toolbar.
Link copied to clipboard
Link copied to clipboard
Returns the title of this toolbar.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun getTitleTextView(): @Nullable TextView
Link copied to clipboard
Link copied to clipboard
Check whether this Toolbar is currently hosting an expanded action view.
Link copied to clipboard
Hide the overflow items from the associated menu.
Link copied to clipboard
open fun inflateMenu(@MenuRes resId: Int)
Inflate a menu resource into this toolbar.
Link copied to clipboard
Only the items in the Menu that were provided by MenuProviders should be removed and repopulated, leaving all manually inflated menu items untouched, as they should continue to be managed manually.
Link copied to clipboard
Returns whether the toolbar will attempt to register its own OnBackInvokedCallback in supported configurations to handle collapsing expanded action items when a back invocation occurs.
Link copied to clipboard
Check whether the overflow menu is currently showing.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun onRtlPropertiesChanged(layoutDirection: Int)
Link copied to clipboard
Link copied to clipboard
open fun removeMenuProvider(@NonNull provider: @NonNull MenuProvider)
Link copied to clipboard
@Nullable
open fun seslGetMenuView(): @Nullable ActionMenuView
Link copied to clipboard
Return the color of the subtitle view.
Link copied to clipboard
Return the color of the title view.
Link copied to clipboard
Gets the top padding that is applied to this Toolbar.
Link copied to clipboard
open fun seslSetSubtitleAlpha(@FloatRange(from = 0.0, to = 1.0) alpha: Float)
Link copied to clipboard
open fun seslSetTitleAlpha(@FloatRange(from = 0.0, to = 1.0) alpha: Float)
Link copied to clipboard
open fun seslSetUserTopPadding(@Px topPadding: Int)
Sets a custom top padding to this Toolbar.
Link copied to clipboard
Sets whether the toolbar will attempt to register its own OnBackInvokedCallback in supported configurations to handle collapsing expanded action items when a back invocation occurs.
Link copied to clipboard
open fun setCollapseContentDescription(@Nullable description: @Nullable CharSequence)
Set a content description for the collapse button if one is present.
Link copied to clipboard
open fun setCollapseIcon(@Nullable icon: @Nullable Drawable)
open fun setCollapseIcon(@DrawableRes resId: Int)
Set the icon to use for the toolbar's collapse button.
Link copied to clipboard
open fun setCollapsible(collapsible: Boolean)
Force the toolbar to collapse to zero-height during measurement if it could be considered "empty" (no visible elements with nonzero measured size)
Link copied to clipboard
open fun setContentInsetEndWithActions(insetEndWithActions: Int)
Sets the start content inset to use when action buttons are present.
Link copied to clipboard
open fun setContentInsetsAbsolute(contentInsetLeft: Int, contentInsetRight: Int)
Sets the content insets for this toolbar.
Link copied to clipboard
open fun setContentInsetsRelative(contentInsetStart: Int, contentInsetEnd: Int)
Sets the content insets for this toolbar relative to layout direction.
Link copied to clipboard
open fun setContentInsetStartWithNavigation(insetStartWithNavigation: Int)
Sets the start content inset to use when a navigation button is present.
Link copied to clipboard
open fun setLogo(drawable: Drawable)
Set a logo drawable.
open fun setLogo(@DrawableRes resId: Int)
Set a logo drawable from a resource id.
Link copied to clipboard
open fun setLogoDescription(@StringRes resId: Int)
open fun setLogoDescription(description: CharSequence)
Set a description of the toolbar's logo.
Link copied to clipboard
open fun setMenu(menu: MenuBuilder, outerPresenter: ActionMenuPresenter)
Link copied to clipboard
Must be called before the menu is accessed
Link copied to clipboard
open fun setNavigationContentDescription(@Nullable description: @Nullable CharSequence)
Set a content description for the navigation button if one is present.
Link copied to clipboard
open fun setNavigationIcon(@Nullable icon: @Nullable Drawable)
open fun setNavigationIcon(@DrawableRes resId: Int)
Set the icon to use for the toolbar's navigation button.
Link copied to clipboard
Set a listener to respond to navigation events.
Link copied to clipboard
Set a listener to respond to menu item click events.
Link copied to clipboard
open fun setOverflowIcon(@Nullable icon: @Nullable Drawable)
Set the icon to use for the overflow button.
Link copied to clipboard
open fun setPopupTheme(@StyleRes resId: Int)
Specifies the theme to use when inflating popup menus.
Link copied to clipboard
open fun setSubtitle(@StringRes resId: Int)
open fun setSubtitle(subtitle: CharSequence)
Set the subtitle of this toolbar.
Link copied to clipboard
open fun setSubtitleTextAppearance(context: Context, @StyleRes resId: Int)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
Link copied to clipboard
open fun setSubtitleTextColor(@NonNull color: @NonNull ColorStateList)
open fun setSubtitleTextColor(@ColorInt color: Int)
Sets the text color of the subtitle, if present.
Link copied to clipboard
open fun setTitle(@StringRes resId: Int)
open fun setTitle(title: CharSequence)
Set the title of this toolbar.
Link copied to clipboard
Link copied to clipboard
open fun setTitleMargin(start: Int, top: Int, end: Int, bottom: Int)
Sets the title margin.
Link copied to clipboard
open fun setTitleMarginBottom(margin: Int)
Sets the bottom title margin in pixels.
Link copied to clipboard
open fun setTitleMarginEnd(margin: Int)
Sets the ending title margin in pixels.
Link copied to clipboard
open fun setTitleMarginStart(margin: Int)
Sets the starting title margin in pixels.
Link copied to clipboard
open fun setTitleMarginTop(margin: Int)
Sets the top title margin in pixels.
Link copied to clipboard
open fun setTitleTextAppearance(context: Context, @StyleRes resId: Int)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
Link copied to clipboard
open fun setTitleTextColor(@NonNull color: @NonNull ColorStateList)
open fun setTitleTextColor(@ColorInt color: Int)
Sets the text color of the title, if present.
Link copied to clipboard
Show the overflow items from the associated menu.